package com.yl.nettylearning.day01;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author yangl
 */
public class TestByteBuffer {
    public static void main(String[] args) {
        //FileChannel
        //1、输入输出流
        //2、RandomAccessFile
        try {
            FileChannel channel = new FileInputStream("test.txt").getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(10);
            //从channel读取，向buffer写入
            channel.read(buffer);
            //打印buffer的内容
            //切换至读模式
            buffer.flip();
            while(buffer.hasRemaining()){
                byte b = buffer.get();
                System.out.println((char)b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
